package com.hxzy.controller.hsbuilding;

import com.alibaba.fastjson.JSONObject;
import com.hxzy.common.BaseServlet;
import com.hxzy.common.ResultAjax;
import com.hxzy.entity.Build;
import com.hxzy.service.BuildService;
import com.hxzy.service.impl.BuildServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description:
 * @Author: ykj
 * @Date: 2022/3/1 21:15
 */

@WebServlet(urlPatterns = "/build/deleteJson")
public class DeleteBuildToJsonServlet extends BaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        try {
            Build build = super.CollectiongParameterToJSON(req, Build.class);
            BuildService service = new BuildServiceImpl();
            int delete = service.delete(build.getId());
            ResultAjax resultAjax = null;
            if (delete > 0) {
                resultAjax = ResultAjax.success("删除成功");
            } else {
                resultAjax = ResultAjax.error("删除失败");
            }
            super.render(resp, JSONObject.toJSONString(resultAjax));
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
